﻿using System;
using System.ComponentModel;
using System.Windows;

namespace Snowdreamist.ComponentModel
{
    [Serializable]
    public class ThreadSafeNotifyPropertyChanged : INotifyPropertyChanged
    {
        protected virtual void OnPropertyChanged(string name)
        {
            if (this.PropertyChanged != null)
            {
                Application.Current.Dispatcher.BeginInvoke(new Action<ThreadSafeNotifyPropertyChanged, PropertyChangedEventArgs>((s, e) =>
                {
                    s.PropertyChanged(s, e);
                }), this, new PropertyChangedEventArgs(name));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
